<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../vue.global.js'></script>
    <script src="https://unpkg.com/lodash@4.17.20/lodash.min.js"></script>
</head>

<body>
    <div id='app'>
        <button @click="onClick1">防抖</button>
        <button @click="onClick2">节流</button>
    </div>
    <script>
        Vue.createApp({
            methods: {
                // 用 Lodash 的防抖函数
                // onClick1: function () {
                //     console.log("onClick");
                // },
                // onClick2: function () {
                //     console.log("onClick");
                // },
                
                onClick1: _.debounce(
                    function () {
                        console.log("onClick");
                    }, 1000
                ),

                onClick2: _.throttle(
                    function () {
                        console.log("onClick");
                    }, 1000
                )
            }
        }).mount('#app')
    </script>
</body>

</html>